feat(posthog): correlate task events with copilot logs via request_id#4453
feat(posthog): correlate task events with copilot logs via request_id#4453waleedlatif1 merged 3 commits intostagingfrom
Conversation
Auto-injects server request_id into all PostHog server events from AsyncLocalStorage context. Adds task_request_started client event fired when SSE traceparent response header arrives, carrying the trace ID used by Go for log correlation. task_generation_aborted now includes the in-flight request_id when available. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview On the client, On the server, Reviewed by Cursor Bugbot for commit 1ed9f52. Configure here. |
Greptile SummaryThis PR wires PostHog event correlation for Sim's AI task features by extracting the W3C trace ID from the
Confidence Score: 5/5Safe to merge — all changes are additive telemetry instrumentation with no impact on existing chat or streaming logic. The trace ID extraction uses a consistent path in both No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant useChat
participant Server
participant PostHog
Client->>Server: POST /api/mothership/chat (userMessageId)
Server-->>Client: HTTP 200, traceparent: 00-{traceId}-{parentId}-01
useChat->>useChat: store traceparent in streamTraceparentRef
useChat->>useChat: extract traceId = traceparent.split('-')[1]
useChat->>Client: onRequestStarted({ requestId: traceId, userMessageId })
Client->>PostHog: captureEvent('task_request_started', { request_id: traceId, user_message_id })
Note over Server,PostHog: Server-side events auto-inject request_id from AsyncLocalStorage
Server->>PostHog: captureServerEvent(any_event) → auto-injects request_id if absent
alt User aborts generation
Client->>useChat: stopGeneration()
useChat->>useChat: getCurrentRequestId() reads streamTraceparentRef
Client->>PostHog: captureEvent('task_generation_aborted', { request_id: traceId })
useChat->>Server: abort stream
useChat->>useChat: clearActiveTurn() → streamTraceparentRef = undefined
end
Reviews (2): Last reviewed commit: "fix(posthog): use traceparent header as ..." | Re-trigger Greptile |
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1ed9f52. Configure here.
Summary
request_idfromAsyncLocalStoragecontext into all PostHog server events (captureServerEvent)task_request_startedclient event fired when SSEtraceparentresponse header arrives, carrying the W3C trace ID used by Go for log correlation (one-to-one withtask_message_sent)request_idintask_generation_abortedwhen availableTest plan
task_message_sentandtask_request_startedboth fire with matching workspace_id and a 32-hexrequest_idtask_generation_abortedcarries the samerequest_id